package com.example.demo;

import org.springframework.beans.factory.InitializingBean;
import org.springframework.stereotype.Component;

import java.util.LinkedList;
import java.util.List;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;

/**
 * Created by martin.xie on 2020/4/28.
 */
@Component
public class MemLeaker implements InitializingBean {
    private List<Object> objs = new LinkedList<>();
    ScheduledExecutorService service = Executors.newScheduledThreadPool(1);

    @Override
    public void afterPropertiesSet() throws Exception {
        service.scheduleAtFixedRate(() -> {
            System.out.println("start add obj...");
            for (int i = 0; i < 50000; i++) {
                objs.add(new Object());
            }
        }, 1000, 1000, TimeUnit.MILLISECONDS);
    }
}